package com.mmlc.meimei.lichengkongjian.mine;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.androidnetframe.utils.LogUtils;
import com.mmlc.inter.InterActivity;
import com.mmlc.meimei.lichengkongjian.Adapter.HistoryGoodsAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.meimei.lichengkongjian.classify.FastGoodsDetailActivity;
import com.mmlc.meimei.lichengkongjian.classify.ProductInfoActivity;
import com.mmlc.network.filter.N1NoParamsRequestFilter;
import com.mmlc.network.responsebean.HistoryGoodsResponseBean;
import com.mmlc.utils.ViewUtils;

import java.util.List;

public class BrowsingHistoryActivity extends InterActivity implements AdapterView.OnItemClickListener {

    @Override
    protected int initContentView() {
        return R.layout.activity_browsing_history;
    }

    GridView grid_browsing;

    @Override
    protected void initView() {
        grid_browsing = ViewUtils.getView(activity, R.id.grid_browsing);
    }

    List<HistoryGoodsResponseBean.DataBean> datas;

    @Override
    protected void initInfo() {
        super.initInfo();
        new N1NoParamsRequestFilter(activity, "myHistory")
                .sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<HistoryGoodsResponseBean>() {
                    @Override
                    public void onSuccess(HistoryGoodsResponseBean result) {
                        if (result != null && result.getData() != null && result.getData().size() > 0) {
                            datas = result.getData();
                            grid_browsing.setAdapter(new HistoryGoodsAdapter(context, result.getData()));
                        }else {
                            LogUtils.e("记录为空","123");
                        }
                    }

                    @Override
                    public void onFailed(View errorLayout, RequestError serverError, int failedType) {

                    }
                });
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        ViewUtils.getView(activity, R.id.iv_back).setOnClickListener(this);
        grid_browsing.setOnItemClickListener(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if(datas.get(position).getIs_zg().equals("1")){
            Intent intent = new Intent(activity, FastGoodsDetailActivity.class);
            intent.putExtra("id", datas.get(position).getId());
            startActivity(intent);
        }else {
            Intent intent = new Intent(activity, ProductInfoActivity.class);
            intent.putExtra("goods_id", datas.get(position).getId());
            startActivity(intent);
        }
    }
}
